package com.example.demo;


import java.text.DecimalFormat;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

/**
 * @author leiliang
 * @version 1.0
 * @Description AtomicInteger 自增ID测试
 * @date 2021/11/23 16:34
 */
public class IdTest {


    private static int totalCount = 0;
    private int customerID;

    public IdTest() {
        ++totalCount;
        customerID = totalCount;
        System.out.println("增加一个");
    }

    public String getCustomerID() {
        DecimalFormat decimalFormat = new DecimalFormat("00000000");
        return decimalFormat.format(customerID);
    }


    public static void main(String args[]) {
        IdTest c1 = new IdTest();
        System.out.println(c1.getCustomerID());
        IdTest c2 = new IdTest();
        System.out.println(c2.getCustomerID());
    }


    private static AtomicLong counter = new AtomicLong(0);

    private static AtomicInteger atomicInteger = new AtomicInteger(0);
    private static String m = "SYS-";

    public String addOne() {
        // long l = (int) counter.incrementAndGet();
        int i = atomicInteger.incrementAndGet();
        String format = String.format("%05d", i);

        return m + format;
    }

}


